package com.yinhanshi.s3test.http;

import com.yinhanshi.s3test.App;
import com.yinhanshi.s3test.R;
import com.yinhanshi.s3test.bean.UploadPieceResponse;

import java.util.Map;

import io.reactivex.Observable;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.HeaderMap;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part;
import retrofit2.http.Query;
import retrofit2.http.Streaming;

public interface MyApi {

    String BASE_URL = App.getInstance().getString(R.string.base_url);
    String BASE_URL_USER = App.getInstance().getString(R.string.base_url_user);
    String BASE_URL_03 = App.getInstance().getString(R.string.base_url_03);

    /**
     * 获取令牌
     */
    @POST("calabash/user/_login")
    Observable<BaseResponseBean> getSignUrl(@Body RequestBody bean);

    /**
     * 上传接口
     */
    @Multipart
    @POST("calabash/file/_upload")
    Observable<UploadPieceResponse> uploadFile(@HeaderMap Map<String, String> headers, @Part MultipartBody.Part part);

    /**
     * 下载接口
     *
     * @param fileId
     * @param startIndex
     * @param endIndex
     * @return
     */
    @Streaming
    @GET("calabash/file/_downloadFile")
    Call<ResponseBody> downloadFile(@Header("Accept-Encoding") String acceptEncoding, @Query("fileId") String fileId,
                                    @Query("startIndex") long startIndex, @Query("endIndex") long endIndex);

}
